<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>复习-继承</title>
</head>
<body>
    <script>
        // 组合继承
        // function Father(sex){
        //     this.name="quan"
        //     this.do=["game","music","code"]
        //     this.sex=sex
        // }
        // Father.prototype.sayName=function(){
        //     console.log('Im '+this.name)
        // }
        // Father.prototype.saySex=function(){
        //     console.log('Im '+this.sex)
        // }
        // Son.prototype=new Father()
        // console.log(Son.prototype.constructor)
        // Son.prototype.constructor=Son
        // console.log(Son.prototype.constructor)
        // function Son(age,sex){
        //     Father.call(this,sex)
        //     this.age=age
        // }
        // Son.prototype.sayAge=function(){
        //     console.log('Im '+this.age)
        // }
        // let instance1=new Son(21,'男')
        // console.log(instance1.name)
        // console.log(instance1.age)
        // instance1.sayName()
        // instance1.saySex()
        // let instance2=new Son(11111,'女')
        // console.log(instance2.name)
        // console.log(instance2.age)
        // instance2.sayAge()
        // instance1.do.push("movie")
        // console.log(instance1.do)
        // console.log(instance2.do)
        // ES6继承
        class Father{
            constructor(sex){
                this.name="quan"
                this.do=["game","music","code"]
                this.sex=sex
            }
            sayName(){
                console.log('Im '+this.name)
            }
            saySex(){ 
                console.log('Im '+this.sex)
            }
        }
        class Son extends Father{
            constructor(age,sex){
                super(sex)
                this.age=age
            }
            sayAge(){
                console.log('Im '+this.age)
            }
        }
        let instance1=new Son(21,'男')
        console.log(instance1.name)
        console.log(instance1.age)
        instance1.sayName()
        instance1.saySex()
        let instance2=new Son(11111,'女')
        console.log(instance2.name)
        console.log(instance2.age)
        instance2.sayAge()
        instance1.do.push("movie")
        console.log(instance1.do)
        console.log(instance2.do)
    </script>
</body>
</html>